/*

 * @FilePath: \Src\App\src\app_key.c
 * @Description: 
 * 
 * Copyright (c) 2025 by ${w}, All Rights Reserved. 
 */

#include "main.h"

void key_gpio_init(void)
{
    rcu_periph_clock_enable(RCU_GPIOA);
    gpio_mode_set(GPIOA, GPIO_MODE_INPUT, GPIO_PUPD_PULLUP, GPIO_PIN_0);
}

unsigned char key1_readbit(void)
{
    return gpio_input_bit_get(GPIOA, GPIO_PIN_0);
}

/**
 * @LastEditTime: 2025-06-14
 * @Description: 按键初始化
 * @return {}
 */
void app_key_create(void)
{
    key_gpio_init();
    ButtonConfig key1 = {
        .id = KEY1,
        .read_keyValue = key1_readbit,
        .trigger_level = 0,
        .button_cb = Key_Event_Handler,
        .event_mask = BUTTON_EVT_CLICK | BUTTON_EVT_LONG_PRESS | BUTTON_EVT_VLONG_PRESS
        // .event_mask = 0
    };
    Button_Register(&key1);
}

void Key_Event_Handler(unsigned char id, ButtonEvent e)
{
    const char *names[] = {"PRESS_DOWN", "RELEASE", "CLICK", "DOUBLE_CLICK", "LONG_PRESS", "VLONG_PRESS", "CONTINUOS_PRESS"};
    PRINT_DEBUG("Button %d: %s", id, names[e]);
    switch (id)
    {
    case KEY1:
        /* code */
        break;
    
    default:
        break;
    }
}




